package com.msc.cili.web.viewcontroller.guestmessagecontroller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.msc.cili.common.api.Result;
import com.msc.cili.common.utils.IPUtil;
import com.msc.cili.repository.entity.guestmessage.GuestMessage;
import com.msc.cili.service.guestmessage.GuestMessageService;
import com.msc.cili.service.guestmessage.bo.GuestMsgBo;
import com.msc.cili.web.viewcontroller.guestmessagecontroller.param.GuestMsgRequestParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 骑蜗牛的羊
 * @date 2023/4/18 22:52
 * <p>留言板</p>
 */
@RestController
@RequestMapping("/msgBoard")
public class MessageBoardController {

    @Autowired
    private GuestMessageService guestMessageService;

    /**
     * 获取留言墙内容
     */
    @GetMapping("/getAllMessage")
    public Result getMsgByPage(@RequestParam(value = "currentPage", defaultValue = "1") int pageIndex,
                               @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        IPage<GuestMessage> msgListByPage = guestMessageService.getMsgListByPage(pageIndex, pageSize);
        return Result.succ(msgListByPage);
    }

    /**
     * 创建留言
     */
    @PostMapping("/msgCreate")
    public Result creageMsg(@RequestBody GuestMsgRequestParam guestMsgRequestParam, HttpServletRequest request) {
        String ipAddr = IPUtil.getIpAddr(request);

      /*  boolean succ = guestMessageService.createMsg( request,guestMsgRequestParam);
        if(succ){
            return Result.succ(200,"创建成功了！",succ);
        }
        return Result.succ(CiliciliErrorCodeEnum.IP_NOT_TODAT.getCode(),CiliciliErrorCodeEnum.IP_NOT_TODAT.getMessage(),succ);*/
        return Result.succ(null);
    }
}
